package com.cskaoyan.user.utils;

import com.cskaoyan.user.dal.entitys.UserVerify;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;

public class SendEmailTask implements Runnable {

    private final JavaMailSender sender;
    private final UserVerify userVerify;
    private final String email;
    private final String urlBase;

    public SendEmailTask(JavaMailSender sender, UserVerify userVerify, String email,
             String urlBase) {
        this.sender = sender;
        this.userVerify = userVerify;
        this.email = email;
        this.urlBase = urlBase;
    }

    @Override
    public void run() {
        SimpleMailMessage message = new SimpleMailMessage();
        message.setFrom("xmu714@qq.com");
        message.setTo(email);
        message.setSubject("csmall商城激活");
        message.setText(String.format(urlBase, userVerify.getUsername(), userVerify.getUuid()));
        sender.send(message);
    }
}
